package top.yoahh.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import top.yoahh.system.entity.SysUser;

public class SecurityUtil {

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static SysUser getUser() {
        return (SysUser) getAuthentication().getPrincipal();
    }

    public static String getUsername() {
        return StringUtils.isEmpty(getUser().getUsername()) ? getUser().getUsername() : "";
    }
}
